/**
 ********************************************************************
 * @author roocket
 * @file    main.c
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate main functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#include "gpio.h"

/**
 * @brief init gpio params
 * @param gpio, gpio value
 * @param power, the data of gpio_settings
 * @param value, the level string
 * @return failed at -1
 */
int gpio_init(int io, struct gpio_settings *power)
{
    int ret = -1;

    power->gpio = io;

    #if 0
    ret = gpio_set_unexport(power,"unexport");
    if ( -1 == ret )
        goto release;
    #endif

    ret = gpio_set_export(power, "export");
    if ( -1 == ret )
        goto release;

    ret = gpio_set_direction(power,1);
    if ( -1 == ret )
        goto release;

    ret = gpio_set_edge_trigger(power, "none");
    if ( -1 == ret )
        goto release;

    ret = gpio_inti_fd(power);
    if ( -1 == ret )
        goto release;

    return 0;

release:
    printf("failed at %s\n",__func__);
    return -1;
}


int main(void)
{
    int ret = -1;
    struct gpio_settings gpio = 
    {
        .direction = "out",
        .level     = 0,
        .fd        = 0,
        .gpio      = 0,
        .data      = 0
    };

    ret = gpio_init(0, &gpio);
    if ( -1 == ret )
    {
        printf("gpio_init failed\n");
        return -1;
    }

    return 0;
}

